package com.doit.beans.day06

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.types.{DataTypes, StructType}

import java.util.Properties

/**
 * @Author:
 * @WX: 17710299606
 * @Tips: 学大数据 ,到多易教育
 * @DOC: https://blog.csdn.net/qq_37933018?spm=1000.2115.3001.5343
 * @Description:
 */
object Demo04_DF_JDBC {
  def main(args: Array[String]): Unit = {

    val session = SparkSession.builder()
      .appName("test")
      .master("local[*]")
      .getOrCreate()

    /**
     * 参数1   url
     * 参数2   表
     * 参数3  Properties   user   password
     */
    val  url = "jdbc:mysql://localhost:3306/doe47"
    val  table  = "ums_user"
    val properties = new Properties()
    properties.setProperty("user" , "root")
    properties.setProperty("password" , "root")
    // 封装连接  封装结果
    val df = session.read.jdbc(url, table, properties)

    df.printSchema()
    df.show()




  }
}